﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace WeiBo.SinaAPI.SinaControllers
{
    public static class WeiBoCommentController
    {
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="xmlUser"></param>
        /// <returns></returns>
        public static SinaMComments GetModelByUserXml(string xmlComment)
        {
            if (!string.IsNullOrEmpty(xmlComment))
            {
                XmlHelper xml = new XmlHelper();
                xml.LoadXml(xmlComment);
                foreach (XmlNode xcomment in xml.SelectNodes("//user"))
                {

                    long id = long.TryParse(xml.SelectSingleNode(xcomment, "id"), out id) ? id : 0;
                    string text = xml.SelectSingleNode(xcomment, "text");
                    string source = xml.SelectSingleNode(xcomment, "source");
                    bool truncated =bool.Parse(xml.SelectSingleNode(xcomment, "truncated"));
                     DateTime  created_at = DateTime.TryParse(StringHelper.SplitDateTime(xml.SelectSingleNode(xcomment, "created_at")), out created_at) ? created_at : DateTime.Now;
                    long user_id =long.Parse(xml.SelectSingleNode(xcomment, "user_id"));
                    long status_id =long.Parse( xml.SelectSingleNode(xcomment, "status_id"));
                    long reply_comment_id =long.Parse(xml.SelectSingleNode(xcomment, "reply_comment_id"));

                    SinaMComments comment = new SinaMComments();
                        comment.id=id;
                        comment.text=text;
                        comment.source = source;
                        comment.truncated = truncated;
                        comment.created_at = created_at;
                        comment.user_id = user_id;
                        comment.status_id = status_id;
                        comment.reply_comment_id = reply_comment_id;

                        return comment;
                }
            }
            return null;
        }
    }
}
